package com.ht.action;

import java.util.List;
import org.apache.struts2.ServletActionContext;
import com.ht.bean.Items;
import com.ht.common.Pager;
import com.ht.service.ItemsService;
import com.opensymphony.xwork2.ActionSupport;

public class ItemsAction extends ActionSupport{
	
	private static final long serialVersionUID = -8744483513745931197L;
	private ItemsService itemsService;
	private Pager<Items> pager;
	private Items items;
	private List<Items> rows;
	private long total;
	private int page;
	
	public void setitemsService(ItemsService itemsService) {
		this.itemsService = itemsService;
	}
	
	
	public Items getItems() {
		return items;
	}

	public void setItems(Items items) {
		this.items = items;
	}

	public long getTotal() {
		return total;
	}
	
	public List<Items> getRows() {
		return rows;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public String add() {
		System.out.println("action add");
		items=itemsService.add(items);
		if(items==null){
			return null;
		}
		return SUCCESS;
	}
	
	public String update(){
		System.out.println("update");
		itemsService.update(items);
		return SUCCESS;
	}
	
	public String delete(){
		System.out.println("delete");
		itemsService.delete(items);
		return SUCCESS;
	}
	
	public String query(){
		System.out.println("query");
		itemsService.query(items);
		return SUCCESS;
	}
	
	public String queryAll(){
		System.out.println("queryAll method");
		pager = new Pager<>();
		pager.setPageNo(page);
		int pageSize = Integer.valueOf(ServletActionContext.getRequest().getParameter("rows"));
		pager.setPageSize(pageSize);
		pager = itemsService.queryAll(pager);
		rows = pager.getRows();
		total = pager.getTotal();
		return SUCCESS;
	}
	
	public String all(){
		System.out.println("all");
		return "all";
	}
}
